﻿@page "/authentication/login"
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.WebUtilities
@layout EmptyLayout
@inject NavigationManager NavigationManager

@attribute [AllowAnonymous]

<div style="height: 100vh; display: flex;" >
    <Card style="width: 510px; height: 500px;  margin: auto;">
        <CardBody>
            <h5 class="text-center mb-lg-5">欢迎</h5>
            <ValidateForm Model="@user"
                          OnValidSubmit="@HandleLogin">
                <BootstrapInput @bind-Value="@user.Email" ShowLabel="false"  PlaceHolder="请输入邮箱"/>
                <BootstrapInput @bind-Value="@user.Password" ShowLabel="false" PlaceHolder="请输入密码" type="password" class="mt-5" />
                <span class="d-flex justify-content-end mt-1 text-caption hover-pointer" 
                      @onclick="OnForgotPassword">
                    已有账号,忘记密码?
                </span>
                <div class="mt-5 d-flex justify-content-center">
                    <Button ButtonStyle="ButtonStyle.Round" IsDisabled="Disable" Color="Color.Primary" ButtonType="ButtonType.Submit" style="height: 46px; width: 320px;">@(Disable?"登录中...":"登录")</Button>
                </div>
                <div class="mt-5 d-flex justify-content-center">
                    <span>没有帐号?&nbsp;</span>
                    <span class="hover-pointer"  @onclick="ToRegisterPage">点此注册</span>
                </div>
            </ValidateForm>

        </CardBody>
    </Card>
</div>



@code {
    UserLogin user = new()
    {
        Email = "a@163.com",
        Password = "12345678"
    };

    bool Disable = false;

    protected override void OnInitialized()
    {
      
    }

    private async Task HandleLogin(EditContext context)
    {
        Disable = true;
        //todo:这里该怎样post到account/login
        Disable = false;
    }

    private async Task OnForgotPassword()
    {

    }

    private async Task ToRegisterPage()
    {
        NavigationManager.NavigateTo("authentication/register",true);
    }
}
